import 'package:backend.core/core/domain/entities/api/web/api_web_purchased_subscription_transaction_offer_type.dart';
import 'package:equatable/equatable.dart';

const kApiWebPurchasedSubscriptionTransactionRegularOfferTypeValue = 'regular';

class ApiWebPurchasedSubscriptionTransactionOfferTypeDto extends Equatable {
  const ApiWebPurchasedSubscriptionTransactionOfferTypeDto._internal({
    required this.offerTypeString,
  });

  final String offerTypeString;

  @override
  List<Object?> get props {
    return [
      offerTypeString,
    ];
  }

  factory ApiWebPurchasedSubscriptionTransactionOfferTypeDto.fromString(String offerTypeString) {
    return ApiWebPurchasedSubscriptionTransactionOfferTypeDto._internal(
      offerTypeString: offerTypeString,
    );
  }

  factory ApiWebPurchasedSubscriptionTransactionOfferTypeDto.fromEntity(
      ApiWebPurchasedSubscriptionTransactionOfferType offerType) {
    late final String offerTypeString;

    if (offerType == ApiWebPurchasedSubscriptionTransactionOfferType.regular) {
      offerTypeString = kApiWebPurchasedSubscriptionTransactionRegularOfferTypeValue;
    }

    return ApiWebPurchasedSubscriptionTransactionOfferTypeDto._internal(
      offerTypeString: offerTypeString,
    );
  }

  @override
  String toString() {
    return offerTypeString;
  }

  ApiWebPurchasedSubscriptionTransactionOfferType toEntity() {
    if (offerTypeString == kApiWebPurchasedSubscriptionTransactionRegularOfferTypeValue) {
      return ApiWebPurchasedSubscriptionTransactionOfferType.regular;
    }

    throw UnimplementedError();
  }
}
